package com.example.metadatatest.ConditionFactories;

import com.example.metadatatest.MetaConfig.AppConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.EnvironmentAware;
import org.springframework.context.annotation.Bean;
import org.springframework.core.env.Environment;

import java.util.Objects;

public class RunLiner  {


    Environment env;

    public RunLiner(Environment env) {
        this.env = env;
    }

    @Bean
    @ConditionalOnProperty(prefix = "wjl.auto",name = "enable",havingValue = "true")
    CommandLineRunner customizeRunLiner(AppConfig appConfig)
    {
        return args -> {
            System.out.println("生成一串随机字符串".concat(Objects.requireNonNull(env.getProperty("random."))));
            System.out.println("开启的端口是"+appConfig.getPort());
        };
    }
}
